package gdou.gym.vo;

import gdou.gym.entity.OrderView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class OrderViewVo extends OrderView implements Comparable<OrderViewVo> {
    private String orderCreateTime;
    private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    private Date date;

    public String getOrderCreateTime() {
        return orderCreateTime;
    }

    @Override
    public String toString() {
        return "OrderViewVo{" +
                "orderCreateTime='" + orderCreateTime +
                '}';
    }

    public OrderViewVo(OrderView orderView) {
        String orderNo = orderView.getOrderNo();
        setOrderNo(orderView.getOrderNo());
        setOrderCost(orderView.getOrderCost());
        setOrderData(orderView.getOrderData());
        setOrderTime(orderView.getOrderTime());
        setOrderSpaceName(orderView.getOrderSpaceName());
        setOrderSpaceSite(orderView.getOrderSpaceSite());
        setState(orderView.getState());
        setOrderUserName(orderView.getOrderUserName());
        setOrderAccount(orderView.getOrderAccount());
        setOrderSpaceNo(orderView.getOrderSpaceNo());
        try {
            date = simpleDateFormat.parse(orderNo.substring(2));
            orderCreateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        } catch (ParseException e) {
            orderCreateTime = null;
        }
    }

    @Override
    public int compareTo(OrderViewVo o) {
        return o.orderCreateTime.compareTo(this.orderCreateTime);
    }
}
